package com.jdiv.samples.arkanoid;

import com.jdiv.JDiv;
import com.jdiv.JProcess;

public class Brick extends JProcess {

	private boolean fallDown=false;
	private int vel=15;
	
	public Brick(int x,int y){
		super();
		graph=2;
		this.x=x;
		this.y=y;
	}
	@Override
	public void begin() {}
	
	public void loop(){
		
		
		if (collision(Main.ball) && !fallDown){
			fallDown=true;
				
			int ang = - (JDiv.fget_angle(x, y, Main.ball.x, Main.ball.y));
			ang = (ang < 0) ? (ang % 360) + 360: ang % 360;
			  
			Main.ball.velX = (int)(((float) Main.ball.vel) * Math.cos(Math.toRadians(ang)) );
			Main.ball.velY = (int)(((float) Main.ball.vel) * Math.sin(Math.toRadians(ang)) );

		}
	
		if (fallDown){
			
			y+=vel;
			if (y>=600) status=JDiv.S_KILL;
		}
		
	}

}
